public class code {
    //求两个链表的相交节点(不能改变原始结构),思路：让长链表先走差值步，然后两者一起走，直到两个指针相同，相交结点就找到了
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        int lenA = 0;
        int lenB = 0;

        ListNode pa = headA;
        ListNode pb = headB;
        //因为后面都一样，那么计算差值两者长度求差值即可
        while(pa != null) {
            lenA++;
            pa = pa.next;
        }
        while(pb != null) {
            lenB++;
            pb = pb.next;
        }
        //让pa和pb重新回到头节点
        pa = headA;
        pb = headB;
        //求差值
        int len = lenA>lenB?lenA-lenB:lenB-lenA;
        //始终让pa指向长链表
        if(lenA<lenB) {
            pa = headB;
            pb = headA;
        }
        //长的链表指针先走差值步
        while(len--!=0) {
            pa = pa.next;
        }
        //pa和pb一起走
        while(pa!= null && pb !=null&&pa != pb) {
            pa = pa.next;
            pb = pb.next;
        }
        return pa;
    }
}
